﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Common.Utilities;
using Common.Utilities.TextMatch;

namespace Workflows.Components.ETL
{
    /// <summary></summary>
    public class CitationAPAStyles
    {
        /// <summary></summary>
        public Dictionary<int, PatternWeight> JournalArticle { get; set; }
        
        /// <summary></summary>
        public Dictionary<int, PatternWeight> Book_Article { get; set; }
        
        /// <summary></summary>
        public Dictionary<int, PatternWeight> Website_Article { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public CitationAPAStyles()
        {
            PatternWeight authorPattern=new PatternWeight()
                                            {
                                                Key=Citation.AuthorField,
                                                Pattern=RegexPatterns.PersonName_LastFM_Multiple,
                                                Required=true,
                                                Weight=1,
                                                MultiMatches=true
                                            };
            PatternWeight pubTimePattern = new PatternWeight()
                                               {
                                                   Key = Citation.PubTimeField,
                                                   Pattern = "\\(?19\\d\\d|200\\d\\)?",
                                                   Required = true,
                                                   Weight = 0.5
                                               };
            PatternWeight titlePattern=new PatternWeight()
                                           {
                                               Key=Citation.TitleField,
                                               Pattern="[^.?!]+",
                                               Required=false,
                                               Weight=0
                                           };
            PatternWeight journalPattern = new PatternWeight()
                                               {
                                                   Key=Citation.JournalField,
                                                   Pattern="[a-zA-Z\\s\\.]+",
                                                   Required=true,
                                                   Weight=0.9
                                               };
            PatternWeight volumePattern = new PatternWeight()
                                              {
                                                  Key = Citation.VolumeField,
                                                  Pattern =
                                                      "\\d+[\\.:]?|" + RegexPatterns.Months + "|" +
                                                      RegexPatterns.Quarters + "|(0[1-9]|1[012])" +
                                                      "\\s+?(19|20)\\d\\d",
                                                  Required = true,
                                                  Weight = 0.75
                                              };
            PatternWeight issuePattern = new PatternWeight()
                                              {
                                                  Key = Citation.IssueField,
                                                  Pattern = "\\(\\d+\\)|:\\d+|\\.\\d+",
                                                  Required = false,
                                                  Weight = 0.3
                                              };
            PatternWeight pagePattern = new PatternWeight()
                                            {
                                                Key = Citation.PageField,
                                                Pattern = "\\d+-*\\d*",
                                                Required = false,
                                                Weight = 0.4
                                            };

            Dictionary<int, PatternWeight> journalPatterns = new Dictionary<int, PatternWeight>();
            journalPatterns.Add(1, authorPattern);
            journalPatterns.Add(2, pubTimePattern);
            journalPatterns.Add(3, titlePattern);
            journalPatterns.Add(4, journalPattern);
            journalPatterns.Add(5,volumePattern);
            journalPatterns.Add(6, pagePattern);
            journalPatterns.Add(7, issuePattern);
            this.JournalArticle = journalPatterns;

            Dictionary<int, PatternWeight> bookPatterns = new Dictionary<int, PatternWeight>();
            PatternWeight authorPattern2 = authorPattern.Clone();
            bookPatterns.Add(1, authorPattern2);
            bookPatterns.Add(2, pubTimePattern.Clone());
            bookPatterns.Add(3, titlePattern.Clone());
            bookPatterns.Add(4,journalPattern.Clone());
            PatternWeight pagePattern2 = pagePattern.Clone();
            pagePattern2.Pattern = "\\(?pp\\.\\s+\\d+-?\\d*\\)?";
            bookPatterns.Add(5,pagePattern2);
            this.Book_Article = bookPatterns;

            Dictionary<int, PatternWeight> websitePatterns = new Dictionary<int, PatternWeight>();
            websitePatterns.Add(1,authorPattern.Clone());
            websitePatterns.Add(2,pubTimePattern.Clone());
            websitePatterns.Add(3, titlePattern.Clone());
            PatternWeight urlPattern = new PatternWeight()
                                           {
                                               Key = Citation.JournalField,
                                               Pattern = RegexPatterns.URL,
                                               Required = true,
                                               Weight = 1
                                           };
            websitePatterns.Add(4, urlPattern);
            this.Website_Article = websitePatterns;
        }

        
    }
}
